package xmpp.androidpush.aidl;

import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;


import xmpp.androidpush.aidl.IPushBinder.Stub;

public class PushBinder {
    private IPushBinder mStub;

    public PushBinder(IBinder binder) {
        this.mStub = Stub.asInterface(binder);
    }

    public void sendMessage(PushMessage msg) {
        try {
            this.mStub.sendMessage(msg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
    public void sendIqMessage(String msg) {
        try {
            if(this.mStub.isConnected()){
                this.mStub.sendIqMessage(msg);
            }else {
                Log.v("PushBinder","disconnectd");
            }

        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public boolean isConnected() {
        try {
            return this.mStub.isConnected();
        } catch (RemoteException e) {
            e.printStackTrace();
            return false;
        }
    }

    public void registerPushListener(IPushListener listener) {
        try {
            this.mStub.registerPushListener(listener);
        } catch (RemoteException e) {
            e.printStackTrace();
        }

    }

    public void unregisterPushListener(IPushListener listener) {
        try {
            this.mStub.unregisterPushListener(listener);
        } catch (RemoteException e) {
            e.printStackTrace();
        }

    }
}
